package com.sinosoft.cnmuseum.utils;

import java.io.FileInputStream;
import java.util.Properties;

import org.apache.log4j.Logger;


public class ConfigUtil {
	
	private static Logger logger = Logger.getLogger(ConfigUtil.class);

	public static final String UPLOADPATH = "uploadpath";
//	public static final String OPENOFFICEPATH = "openofficepath";
//	public static final String PDFPATH = "pdfpath";
//	public static final String UPLOADPATH = "uploadpath";
//	public static final String ZIPPATH = "zippath";
//	public static final String SOLRDBURL = "solrdburl";
//	public static final String SOLRFILEURL = "solrfileurl";
//	public static final String GGORGSURL = "ggorgsurl";
//	public static final String APPID = "appid";
	
	private static Properties properties = new Properties();

	static {
		String path = "";
		try {
			System.out.println("初始化系统配置");
			logger.info("初始化系统配置");
			path =ConfigUtil.class.getResource("/").getPath();
			System.out.println("*****"+path);
			path = path.replaceAll(" ", "");
			// windows文件路径问题
			path = path.substring(0, path.indexOf("classes")).replaceAll("%20", " ");
			FileInputStream fis = new FileInputStream(path+ "config.properties");
			properties.load(fis);
			fis.close();
			System.out.println("初始化系统配置成功");
			logger.info("初始化系统配置成功");
		} catch (Exception ex) {
			System.out.println("初始化系统配置失败");
			logger.error("初始化系统配置失败");
			System.out.println("读取系统配置文件 " + path + " 错误. Cause by:"+ex.getMessage());
			logger.error("读取系统配置文件 " + path + " 错误. Cause by:"+ex.getMessage());
		}
	}
	
	/**
	 * 依据Key取得配置内容
	 * 
	 * @param key
	 * @return
	 */
	public static String getProperty(String key) {
		return properties.getProperty(key);
	}

	public static Properties getProperties() {
		return properties;
	}
}
